Repository navigation
Let agents call tools the app writes in Swift - #6
Merged
Merged
Conversation
HostTools in a HostToolKit, passed as WorkflowExecutor(hostToolKits:), run in-process through the same path as server tools: the write policy, the tool-call limit and read-only policies apply, without network or connector. Steps select them by kit id, so workflows stay Codable.
ToolSources maps each id to where its tools come from: requests, a server, host tools, or an id both kinds claim. Every lookup is one exhaustive switch, and recovery still fingerprints only the Codable kits.
Juanpe
force-pushed
the
feat/host-tools
branch
from
October 28, 2026 12:02
7cd134a to
129d7aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 What
Adds host tools:
HostTools grouped in aHostToolKitand passed asWorkflowExecutor(hostToolKits:). These are tools the app writes in Swift, such as one that edits the app's own state. Agent and Use a Tool steps select them by kit id, like anyToolKit.Stacked on #5 (it uses nested fields in its tests and touches the same validation code). Review that one first; this PR's base moves to
mainonce it merges.🤔 Why
AgentToolcan only send an HTTP request. When the action belongs to the app, for example "add two beers to the order on screen", the app had to stand up a fake server or an MCP connector and route the call back to itself, and local-only executions refused it as network access.🛠 How it works
ToolServerConnectionthroughServerToolCallandcallServerTool, so the existing rules apply unchanged: the six-call limit,.readOnly/.noTools, events, traces, and "never retried, uncertain once dispatched".changesSomething: false; those calls ask thewritePolicy, which seesPOST host:<kit id>with the tool and its arguments in the body.StepandToolKitJSON shapes are unchanged.ToolKitand aHostToolKit, duplicate tool names, and invalid parameter schemas.ToolSourcesvalue, which maps each id to aToolSource:.requests,.server,.host, or.ambiguouswhen both kinds claim the id. Agents, Use a Tool, policies, recovery and validation each handle the sources with one exhaustiveswitch. The publicinitkeeps separatetoolKits:andhostToolKits:, since one is Codable data and the other in-memory code.🧪 How it was tested
HostToolTests(ScriptedModel, no network):LiveAppleTests.onDeviceModelCallsAHostTool: Apple's on-device model on macOS 27 callsaddLine(product: Beer, quantity: 2)for "Two beers, please." All five live tests pass withRELAY_LIVE=1.make check-style,make check-skill, and an iOS build of the four libraries.✅ Checklist
make formatandmake check-stylepass.env -u RELAY_LIVE swift test -Xswiftc -warnings-as-errorspasses.ScriptedModel/StubProtocol, without live services or keys.CHANGELOG.mdunderUnreleased.📣 Notes for review
hostToolKits:parameter.start/resumecovers changes to them, and the recovery definition stays byte-identical for existing checkpoints.effectivePolicynow reads templates only from request kits. Before, it also read thetoolsof a kit that has a server, but those never run (server kits only offer the server's tools), so they no longer narrow a step's data access.Workflow+ToolValidation.swift.validationIssuesdrops to 69 lines (under the 80-line error limit) andvisitto complexity 20. Their three baseline entries are updated to the lower numbers rather than added.